@extends('common.admin_template')

@section('content')
    <link rel="stylesheet" type="text/css" href="{{asset('css/daterangepicker.css')}}" />
    <div class="boxWidth">
        @include('common.notice_msg')
        <?php
            $type = isset($_GET["type"])?$_GET["type"]:'';
            $id = isset($_GET["id"])?$_GET["id"]:'';
            $item = isset($_GET["item"])?$_GET["item"]:'';
        ?>
        <div class="row searchLine">
            <div class="col-xs-8 ">
                选择时间：<input id="datefilter" type="text" name="datefilter" readonly  class="searchSelect" style="text-align: center" value="{{isset($_GET["start"])?$_GET["start"].'/'.$_GET["end"]:''}}">
                @if(!$id)
                    <select id="cat" class="searchSelect">
                        <option value="">全部申请</option>
                        <option value="user" @if($type==='user') selected="selected"  @endif>入驻申请</option>
                        <option value="active" @if($type==='active') selected="selected"  @endif>活动申请</option>
                        <option value="join" @if($type==='join') selected="selected"  @endif>活动预约</option>
                        <option value="service" @if($type==='service') selected="selected"  @endif>服务预约</option>
                        <option value="coupon" @if($type==='coupon') selected="selected"  @endif>优惠券申请</option>
                    </select>
                @endif
                <button class="btn btn-default searchBtn" id="searchMore">筛选</button>
            </div>
            <div class="col-xs-4 searchInput">
                @if($id)
                    <a href="{{asset('excel/export?id='.$id.'&item='.$item.'&export=form'.(isset($_GET["start"])?'&start='.$_GET["start"].'&end='.$_GET["end"]:'').(isset($_GET["page"])?'&page='.$_GET["page"]:''))}}"><button class="btn btn-default searchBtn">下载</button></a>
                @elseif(($type=='user'||$type=='active')&&count($Forms))
                    <a href="{{asset('excel/export?type='.$type.'&export=form'.(isset($_GET["start"])?'&start='.$_GET["start"].'&end='.$_GET["end"]:'').(isset($_GET["page"])?'&page='.$_GET["page"]:''))}}"><button class="btn btn-default searchBtn">下载</button></a>
                @endif
            </div>
        </div>
        <table class="table table-hover adminTableBg">
            @if($id)
                <thead>
                <tr>
                    <?php $num = count($Name)?>
                    @foreach($Name as $n)
                        @if(!isset($n->type)||$n->type !== 'title')
                            <th class="col-xs-1">{{$n->name}}</th>
                        @endif
                    @endforeach
                    @if(count($Forms)&&$Forms[0]->type === 'coupon')
                        <th class="col-xs-1">状态</th>
                        <?php $couponStatus = ["待审","已通过","已拒绝"] ?>
                    @endif
                    <th class="col-xs-1">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($Forms as $Form)
                    <tr>
                        @foreach($Form->form as $F)
                        <th class="col-xs-1 itemTd">{{$F}}</th>
                        @endforeach
                        <?php
                            if($item==0){
                                for ($i = count($Form->form);$i<$num;$i++){
                                    echo '<th class="col-xs-1 itemTd"></th>';
                                }
                            }
                        ?>
                        @if($Forms&&$Forms[0]->type === 'coupon')
                            <th class="col-xs-1 itemTd">{{$couponStatus[$Form->status]}}</th>
                        @endif
                        <th class="col-xs-1 itemTd">
                            @if($Form->type === 'coupon'&&$Form->status == 0)
                                <a href="{{url('admin/form/coupon',['id' => $Form->id ,'status' => 1])}}"><span class="openLive">通过</span></a>
                                <a href="{{url('admin/form/coupon',['id' => $Form->id ,'status' => 2])}}"><span class="liveUser" onclick="if(!confirm('是否确认拒绝？'))return false">拒绝</span></a>
                            @endif
                            <a href="{{url('admin/form/edit',['id' => $Form->id])}}"><span>详情</span></a>
                            <a href="{{url('admin/form/del',['id' => $Form->id])}}"><span class="redColor" onclick="if(!confirm('是否确认删除？'))return false">删除</span></a>
                        </th>
                    </tr>
                @endforeach
                </tbody>
            @elseif($type=='active')
                <thead>
                <tr>
                    <th class="col-xs-2">活动名称</th>
                    <th class="col-xs-2">城市地区</th>
                    <th class="col-xs-2">地址</th>
                    <th class="col-xs-1">人数</th>
                    <th class="col-xs-1">主办方</th>
                    <th class="col-xs-1">票价</th>
                    <th class="col-xs-2">开始时间</th>
                    <th class="col-xs-1">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($Forms as $Form)
                    <tr>
                        <th class="col-xs-2 itemTd">{{$Form->form->name}}</th>
                        <th class="col-xs-2 itemTd">{{$Form->form->city.' '.$Form->form->area}}</th>
                        <th class="col-xs-2 itemTd">{{$Form->form->address}}</th>
                        <th class="col-xs-1 itemTd">{{$Form->form->peoples}}</th>
                        <th class="col-xs-1 itemTd">{{$Form->form->organizers}}</th>
                        <th class="col-xs-1 itemTd">{{$Form->form->price}}</th>
                        <th class="col-xs-2 itemTd">{{$Form->form->activeTime}}</th>
                        <th class="col-xs-1 itemTd">
                            <a href="{{url('admin/form/edit',['id' => $Form->id])}}"><span>详情</span></a>
                            <a href="{{url('admin/form/del',['id' => $Form->id])}}"><span class="redColor" onclick="if(!confirm('是否确认删除？'))return false">删除</span></a>
                        </th>
                    </tr>
                @endforeach
                </tbody>
            @elseif($type=='user')
                <thead>
                <tr>
                    <th class="col-xs-2">用户名</th>
                    <th class="col-xs-2">联系人</th>
                    <th class="col-xs-2">联系电话</th>
                    <th class="col-xs-3">公司信息</th>
                    <th class="col-xs-2">申请时间</th>
                    <th class="col-xs-1">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($Forms as $Form)
                    <tr>
                        <th class="col-xs-2 itemTd">{{$Form->name}}</th>
                        <th class="col-xs-2 itemTd">{{$Form->form[0]}}</th>
                        <th class="col-xs-2 itemTd">{{$Form->form[1]}}</th>
                        <th class="col-xs-3 itemTd">{{$Form->form[2]}}</th>
                        <th class="col-xs-2 itemTd">{{$Form->created_at}}</th>
                        <th class="col-xs-1 itemTd">
                            <a href="{{url('admin/form/edit',['id' => $Form->id])}}"><span>详情</span></a>
                            <a href="{{url('admin/form/del',['id' => $Form->id])}}"><span class="redColor" onclick="if(!confirm('是否确认删除？'))return false">删除</span></a>
                        </th>
                    </tr>
                @endforeach
                </tbody>
            @else
                <thead>
                <tr>
                    <th class="col-xs-2">用户</th>
                    <th class="col-xs-4">页面</th>
                    <th class="col-xs-2">分类</th>
                    <th class="col-xs-2">时间</th>
                    <th class="col-xs-2">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($Forms as $Form)
                    <tr>
                        <th class="col-xs-2 itemTd">{{$Form->name}}</th>
                        <th class="col-xs-4 itemTd"><a href="{{asset('admin/form').($Form->type!='active'&&$Form->type!='user'?'?id='.$Form->parent.'&&item='.$Form->item:'?type='.$Form->type)}}">{{$Form->title?$Form->title:$Form->typeName}}</a></th>
                        <th class="col-xs-2 itemTd">{{$Form->typeName}}</th>
                        <th class="col-xs-2 itemTd">{{$Form->created_at}}</th>
                        <th class="col-xs-2 itemTd">
                            <a href="{{url('admin/form/edit',['id' => $Form->id])}}"><span>详情</span></a>
                            <a href="{{url('admin/form/del',['id' => $Form->id])}}"><span class="redColor" onclick="if(!confirm('是否确认删除？'))return false">删除</span></a>
                        </th>
                    </tr>
                @endforeach
                </tbody>
            @endif
        </table>
        @if(!isset($_GET["start"]))
            <div class="pull-right">
                <?php
                $url = Array();
                if($type){
                    $url["type"] = $type;
                }
                if($id){
                    $url["id"] = $id;
                }
                if($item){
                    $url["item"] = $item;
                }
                ?>
                {!! $Forms->appends($url)->render() !!}
            </div>
        @endif
    </div>
@stop
@section('js')
    <script src="{{asset('js/moment.min.js')}}"></script>
    <script src="{{asset('js/daterangepicker.js')}}"></script>
    <script>
        $(function() {
            $('input[name="datefilter"]').daterangepicker({
                autoUpdateInput: false,
                locale: {
                    applyLabel: '确定',
                    cancelLabel: '清除',
                    fromLabel : '起始时间',
                    toLabel : '结束时间',
                    daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
                    monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
                        '七月', '八月', '九月', '十月', '十一月', '十二月' ],
                    firstDay : 1
                }
            });
            $('input[name="datefilter"]').on('apply.daterangepicker', function(ev, picker) {
                $(this).val(picker.startDate.format('YYYY-MM-DD') + '/' + picker.endDate.format('YYYY-MM-DD'));
            });

            $('input[name="datefilter"]').on('cancel.daterangepicker', function(ev, picker) {
                $(this).val('');
            });

            $('#searchMore').on('click',function () {
                var t = $('#datefilter').val(),cat = $('#cat').val(),id = '',item = '',url = '';
                {{$id?'id = '.$id:''}}
                if(cat){
                    url += 'type='+cat+'&';
                }
                if(id){
                    url += 'id='+id+'&';
                    {{$item?'item = '.$item:''}}
                    if(item){
                        url += 'item='+item+'&';
                    }
                }
                if(t){
                    var tArr = t.split('/'),start = tArr[0], end = tArr[1];
                    url += 'start='+start+'&'+'end='+end;
                }
                window.location.href= "{!! url('admin/form?') !!}"+url;
                {{--if(tag!=0||cat!=0){--}}
                    {{--window.location.href= "{!! url('admin/services?') !!}"+(tag==0?'':'tag='+tag)+(cat==0?'':'&cat='+cat);--}}
                {{--}else{--}}

                {{--}--}}
            });
        });
    </script>
@stop